package demo12.gumballRemote;

public class WinnerState implements State {
	private static final long serialVersionUID = 2L;
    transient GumballMachine gumballMachine;
 
    public WinnerState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }
 
    @Override
   	public void insertQuarter() {
   		System.out.println("请稍等，我们已经给你一个口香");
   	}
    
   	@Override
   	public void ejectQuarter() {
   		System.out.println("请稍等，我们已经给你一个口香");
   	}
    
   	@Override
   	public void turnCrank() {
   		System.out.println("转了两圈不会让你另一个口香糖!");
   	}
    
   	@Override
   	public void dispense() {
   		gumballMachine.releaseBall();
   		if (gumballMachine.getCount() == 0) {
   			gumballMachine.setState(gumballMachine.getSoldOutState());
   		} else {
   			gumballMachine.releaseBall();
   			System.out.println("你是中奖者你获得了两个糖果");
   			if (gumballMachine.getCount() > 0) {
   				gumballMachine.setState(gumballMachine.getNoQuarterState());
   			} else {
               	System.out.println("正在出糖果!");
   				gumballMachine.setState(gumballMachine.getSoldOutState());
   			}
   		}
   	}
   	
   	@Override
   	public String toString() {
   		return "分配两个糖果给你，因为你是中奖者!";
   	}
}
